package com.hmkj.core.mapper.account;

import com.hmkj.common.baseMapper.GenericMapper;
import com.hmkj.core.model.account.AccountRechargeModel;
import com.hmkj.core.po.account.AccountRecharge;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * 充值记录相关Dao接口<br>
 *
 * @author eproo
 * @date   2018-07-05 09:50:54
 */
public interface AccountRechargeMapper extends GenericMapper<AccountRecharge,Integer> {

    @Select("SELECT t.*,u.user_name AS 'u.userName',u.mobile_phone AS 'u.mobilePhone' FROM biz_account_recharge t LEFT JOIN biz_user u ON u.id = t.user_id WHERE 1=1 ${whereSql} ${sortSql} limit ${nowPage}, ${pageSize} ")
    List<AccountRechargeModel> findListBySqlJoin(Map<String, Object> params);

    @Select("SELECT count(1) FROM biz_account_recharge t LEFT JOIN biz_user u ON u.id = t.user_id WHERE 1=1 ${whereSql}")
    long countBySqlJoin(Map<String, Object> params);

    /**
     * 前台充值列表
     *
     * @param param 参数集合
     * @return List<Recharge>
     */
    @Select(" <script> SELECT t.* " +
            "FROM biz_account_recharge t " +
            "WHERE t.user_id = #{userId} AND t.del_flag = 1 " +
            "<if test=\"type != null and type != ''\"> AND t.`type` = #{type} </if>" +
            "ORDER BY t.create_time DESC </script>")
    List<AccountRecharge> findListForRechargeList(Map<String, Object> param);

    /**
     * 前台充值列表
     *
     * @param param 参数集合
     * @return Integer
     */
    @Select(" <script> SELECT count(*) " +
            "FROM biz_account_recharge t " +
            "WHERE t.user_id = #{userId} AND t.del_flag = 1 " +
            "<if test=\"type != null and type != ''\"> AND t.`type` = #{type} </if>" +
            "ORDER BY t.create_time DESC </script>")
    Integer findCountForRechargeList(Map<String, Object> param);

    /**
     * 通过用户id和订单号查询充值订单
     * @param orderId   订单号
     * @return          订单
     */
    @Select("SELECT t.* FROM fm_recharge t WHERE t.del_flag = 1  AND t.order_no = #{orderId}")
    AccountRecharge findByUserIdAndOrderNo(String orderId);
}
